<?
require_once("../config/dbconn.php");require_once("../config/usercls.php");require_once("pwd1cls.php");
if ($glo_closetjnet==1){
	die("推荐网关闭了");
}
//获取当前会员
$curusername=$_SESSION['sys_username'];
$sqlchk="select * from {$db_prefix}applyzmd where username='".$_SESSION['sys_username']."' and state=1";
	$rschk=$db->get_one($sqlchk);
	if ($rschk){
		
		$isbdzx2=1;
		
	}
	else
	{
		$isbdzx2=0;
	}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-image: url(image1/bg-body.png);
}
td{
	font-size:12px;
}
-->
</style>

<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/navbg1.png"><img src="images/left-top-right1.png" width="17" height="29" /></td>
    <td width="100%" height="29" valign="top" background="images/navbg1.png"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">&nbsp;&nbsp;推荐网体</div></td>
      </tr>
    </table></td>
    <td width="16" valign="top" background="images/navbg1.png"><img src="images/nav-right-bg.png" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg1.png">&nbsp;</td>
    <td valign="top" >
	
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td valign="top">
		<table width="60%" align="center" cellspacing="1">  
    <?
		foreach($hyrankary as $k1=>$v1){
	?>
	  <TD width="60" height="25" align="right" valign="middle" bgColor="<?php echo $hycolorary[$k1];?>"><font color="#FFFFFF"><? echo $v1?></font></TD>	
	  <?
	  }
	  ?>
	  </table>	
	  <form action="" method="get" name="form1" id="form1">
	  <table width="100%" border="0">
		<tr>
		<td height="30" align="center">
		  <input type="hidden" name="action" value="query"><span id="Label1">用户名：</span><input name="username" type="text" id="username" size="10">
				  <input type="submit" name="bgt" value="搜索"></td>
		</tr>
	</table>
	</form>


	<?php
	if ($action=='query'){
		if (trim($username)!=''){
			$sqlhy="select * from {$db_prefix}users where username='".trim($username)."'";
			$rshy=$db->get_one($sqlhy);
			
			$sqlchk="select * from {$db_prefix}applyzmd where username='".$_SESSION['sys_username']."' and state=1";
			$rschk=$db->get_one($sqlchk);
			if ($rschk){
				$isbdzx=1;				
			}
			else
			{
				$isbdzx=0;
			}
			if($isbdzx==0)
			{
				echo "<script>alert('不是服务中心只能查看一层');history.back();</script>";exit();
			}
			if ($rshy){
				$curusername=$rshy["username"];
				//查询的会员是否在推荐网体之下
				if (trim($username)!=$_SESSION['sys_username']){
					$sqlgx="select tjstr from {$db_prefix}tjgx where userid='".$rshy['id']."'";
					$rsgx=$db->get_one($sqlgx);
					/*$tjnetary=explode(',',$rsgx['tjstr']);
					if (!in_array($_SESSION['sys_userid'],$tjnetary)){
						die("查询会员不在您的推荐网内");
					}*/
				}
			}else die("没有此会员");
		}
	}
	
	
	
	if ($curusername){
		$sql11="select * from {$db_prefix}users where username='".$curusername."'";
		$rs11=$db->get_one($sql11);
		//会员是否是最顶层的，不是最顶层的，那么就显示一个上一层按钮
		if (($rs11["tjuser"])&&($curusername!=$_SESSION['sys_username'])){
		?>
		<div align="center">
		<input type="button" name="btn1" value="上一层" id="btn1"  onClick="location.href='?username=<? echo $rs11["tjuser"]?>&action=query';">
		<input type="button" name="btn2" value="置顶" id="btn2" onClick="location.href='?username=<? echo $rs_hy["username"]?>&action=query';">
		</div>
		<?
		}
		?>
					
	    <table align="center" cellpadding="0" cellspacing="0" width="100%">
	      <tr>
            <td align="center" valign="top"><table width="100" border="0" cellspacing="1" cellpadding="0" bgcolor="silver" style="margin:0px 3px;">
              <tr>
                <td height="20" align="center" bgcolor="<?php echo $hycolorary[$rs11["rank"]]?>"><a style="WIDTH: 100px;" href="?username=<? echo urlencode($rs11["username"])?>&action=query"><font color="ffffff"><strong><? echo $rs11["username"]?></strong></font></a></td>
              </tr>
              <tr>
                <td height="20" align="center" bgcolor="#FFFFFF" ><? echo $hyrankary[$rs11["rank"]]?></td>
              </tr>
              <tr>
                <td height="20" align="center" bgcolor="#FFFFFF" ><table width="100" border="0" cellpadding="0" cellspacing="1" bgcolor="#C0C0C0">
                  <tbody bgcolor="#FFFFFF">
                    <tr>
                      <td align="center">直</td>
                      <td align="center"><?
					  $sqltj="select count(id) as c from {$db_prefix}users where tjuser='".$rs11['username']."'";
					  $rstj=$db->get_one($sqltj);
					  echo intval($rstj['c']);
					  ?>
                      </td>
                    </tr>
                    <tr>
                      <td align="center">总</td>
                      <td align="center"><?
					  //获取总的会员
					 /* $sqltj="select count(id) as c from {$db_prefix}tjgx where find_in_set('".$rs11['id']."',tjstr)>0";
					  $rstj=$db->get_one($sqltj);
					  echo intval($rstj['c']);*/
					  $sqltj="select tjnum from {$db_prefix}users where username='".$rs11['username']."'";
					  $rstj=$db->get_one($sqltj);
					  $tjnumstr=$rstj["tjnum"];
					  $arrtjnum=split(',',$tjnumstr);
					  $total=0;
					  foreach($arrtjnum as $num){    $total+=$num;}
					  echo intval($total);
					  ?></td>
                    </tr>
                  </tbody>
                </table></td>
              </tr>
              <tr>
                <td height="20" align="center" bgcolor="#FFFFFF" ><? echo date("Y-m-d",$rs11["regtime"]);?></td>
              </tr>
			  <?php if($isbdzx2==1){?>
			   <tr>
                          <td height="20" align="center" bgcolor="#FFFFFF"><a href="user_reg.php?id=<?=$rshy['id']?>&pageno=<?=$page->pageno?>">注册</a></td>
                        </tr>
				 <?php } ?>
            </table></td>
	        </tr>
          <tr>
            <td><?
$sql1="select count(id) as c from {$db_prefix}users where tjuser='".$rs11["username"]."'";
$rs_c=$db->get_one($sql1);
if ($rs_c["c"]>0){
?>
                <table border="0" align="center" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                  </tr>
                </table>
  <?
}


//冒泡求解
function tjnettree($tj_username,$dtp,$dtp1,$flag){
global $db,$db_prefix,$action,$hycolorary,$hyrankary;
if ($dtp1<=$dtp){
?>
   <table align="center" cellpadding="0" cellspacing="0">
   <tr>
	 <?
	$sql="select * from {$db_prefix}users where tjuser='".$tj_username."'";
	$result=$db->query($sql);
	$c_num=$db->num_rows($result); $i=1;
	while ($rs=$db->fetch_array($result)){
	?>
	
    <td align="center" valign="top">
	<?
	if ($c_num>1){
	?>
	<?
	if (($i==1) && ($c_num>$i)){
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" ></td>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                </tr>
                              </table>
                                <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                          </tr>
                        </table>
                      <?
	}else if(($i>1) && ($c_num==$i)){
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                  <td width="50%" height="1" ></td>
                                </tr>
                              </table>
                                <img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                          </tr>
                        </table>
	<?
	}else{
	?>
                        <table border="0" cellspacing="0" cellpadding="0" width="100%">
                          <tr>
                            <td align="center"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                  <td width="50%" height="1" bgcolor="silver"></td>
                                </tr>
                              </table>
                                <img src="images/line.gif" alt="" width="27" border="0" style="WIDTH: 1px; HEIGHT: 20px" /></td>
                          </tr>
                        </table>
                      <?
	}
	}
	?>
                      <table width="100" border="0" cellspacing="1" cellpadding="0" bgcolor="silver" style="margin:0px 3px;">
                        <tr>
                          <td height="20" align="center" bgcolor="<?php echo $hycolorary[$rs["rank"]]?>"><a style="WIDTH: 100px; BACKGROUND-COLOR: <? echo $hycolorary[$rs["rank"]]?>" href="?username=<? echo urlencode($rs["username"])?>&action=query"><font color="ffffff"><strong><? echo $rs["username"]?></strong></font></a></td>
                        </tr>
                        <tr>
                          <td height="20" align="center" bgcolor="#FFFFFF"><? echo $hyrankary[$rs["rank"]]?></td>
                        </tr>
                        <tr>
                          <td height="20" align="center" bgcolor="#FFFFFF"><table width="100" border="0" cellpadding="0" cellspacing="1" bgcolor="#C0C0C0">
                            <tbody bgcolor="#FFFFFF">
                              <tr>
                                <td align="center">直</td>
                                <td align="center"><?
					  $sqltj="select count(id) as c from {$db_prefix}users where tjuser='".$rs['username']."'";
					  $rstj=$db->get_one($sqltj);
					  echo intval($rstj['c']);
					  ?></td>
                              </tr>
                              <tr>
                                <td align="center">总</td>
                                <td align="center"><?
					  //获取总的会员
					  $sqltj="select count(id) as c from {$db_prefix}tjgx where find_in_set('".$rs['id']."',tjstr)>0";
					  $rstj=$db->get_one($sqltj);
					  echo intval($rstj['c']);
					  ?></td>
                              </tr>
                            </tbody>

                          </table></td>
                        </tr>
                        <tr>
                          <td height="20" align="center" bgcolor="#FFFFFF"><? echo date("Y-m-d",$rs["regtime"])?></td>
                        </tr>
						 <?php if($flag){
							
							?>
							
			   <tr>
                          <td height="20" align="center" bgcolor="#FFFFFF"><a href="user_reg.php?id=<?=$rs['id']?>&pageno=<?=$page->pageno?>">注册</a></td>
                        </tr>
				 <?php } ?>
                      </table>
                      <?
	$sql1="select count(id) as c from {$db_prefix}users where tjuser='".$rs["username"]."'";
	$rs1=$db->get_one($sql1);
	?>
                        <div style="display:block" id="table_<? echo $rs["id"]?>">
                          <?
	if ($dtp1<$dtp){
	?>
                          <?
	if ($rs1["c"]>0){
	?>
                          <table align="center" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td align="center"><img style="WIDTH: 1px; HEIGHT: 20px" alt="" src="images/line.gif" border="0" /></td>
                            </tr>
                          </table>
                          <?php
	}
	?>
                          <?php
	if ($rs1["c"]==1){
	?>
                          <table align="center" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td align="center"><img src="images/line.gif" alt="" width="8" border="0" style="WIDTH: 1px; HEIGHT: 20px" /></td>
                            </tr>
                          </table>
                          <?php
	}
	?>
                          <?php
	}
	?>
                          <?
	tjnettree($rs["username"],$dtp,$dtp1+1,$flag);
	?>
                      </div></td>
                    <?php
	$i++;
}
$db->free_result($result);
?>
                  </tr>
                </table>
				  <?php
	}
	}
	 //无限的查看拓扑图
	tjnettree($rs11["username"],1,1,$isbdzx2);
}
?>           
<BR><BR><BR><BR>

</td>
          </tr>
        </table>	    </td>
      </tr>
    </table></td>
    <td background="images/mail_rightbg.png">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.png"><img src="images/buttom_left2.png" width="17" height="17" /></td>
      <td height="17" valign="top" background="images/buttom_bgs.png">&nbsp;</td>
      <td background="images/mail_rightbg.png"><img src="images/buttom_right2.png" width="16" height="17" /></td>
  </tr>
</table>

</body>
</html>